package com.dede.net_speed_monitor.util;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;

/**
 * Created by hsh on 2017/5/11 011 下午 05:17.
 * 通知栏网速图标工厂
 */
public class NetTextIconFactory {

    /**
     * 创建下载图标
     *
     * @param text1 下载速度
     * @param text2 单位
     * @return bitmap
     */
    public static Bitmap createSingleIcon(String text1, String text2) {
        Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setTextSize(60f);
        paint.setTypeface(Typeface.DEFAULT_BOLD);
        paint.setTextAlign(Paint.Align.CENTER);
        paint.setColor(Color.WHITE);
        Paint.FontMetrics fontMetrics = paint.getFontMetrics();
        int textY = (int) ((Math.abs(fontMetrics.top) - fontMetrics.descent) + .5);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawText(text1, 50, textY + 5, paint);

        paint.setTextSize(40f);
        fontMetrics = paint.getFontMetrics();
        int text2Y = (int) ((Math.abs(fontMetrics.top) - fontMetrics.descent) + .5);
        canvas.drawText(text2, 50, textY + 5 + text2Y + 10, paint);
        return bitmap;
    }

    /**
     * 创建上传下载的图标
     *
     * @param text1 上行网速
     * @param text2 下行网速
     * @return bitmap
     */
    public static Bitmap createDoubleIcon(String text1, String text2) {
        Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setTextSize(50f);
        paint.setTypeface(Typeface.DEFAULT_BOLD);
        paint.setTextAlign(Paint.Align.CENTER);
        paint.setColor(Color.WHITE);
        Paint.FontMetrics fontMetrics = paint.getFontMetrics();
        int textY = (int) ((Math.abs(fontMetrics.top) - fontMetrics.descent) + .5);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawText(text1, 50, textY + 5, paint);

        paint.setTextSize(50f);
        fontMetrics = paint.getFontMetrics();
        int text2Y = (int) ((Math.abs(fontMetrics.top) - fontMetrics.descent) + .5);
        canvas.drawText(text2, 50, textY + 5 + text2Y + 10, paint);
        return bitmap;
    }
}
